package com.lbl.servlet;

import com.lbl.bean.Contact;
import com.lbl.service.ContactService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/list")
public class ContactListServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1:创建业务类对象
        ContactService contactService = new ContactService();
        //2:调用查询
        List<Contact> contactList = contactService.queryAll();
        //3:遍历打印，改成请求转发，并且使用el与jstl来展示
        request.setAttribute("list",contactList);
        request.getRequestDispatcher("/list.jsp").forward(request,response);
    }
}
